package pages;

import static org.openqa.selenium.support.ui.ExpectedConditions.alertIsPresent;
import static org.openqa.selenium.support.ui.ExpectedConditions.presenceOfElementLocated;

import model.Film;

import org.openqa.selenium.By;
import org.openqa.selenium.TimeoutException;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;
import org.openqa.selenium.support.ui.Select;


public class FilmViewPage extends InternalPage {


	public FilmViewPage(PageManager pages) {
		super(pages);
	}

	@FindBy(css = "img[alt=\"Edit\"]")
	private WebElement editButton;

	@FindBy(css="img[alt=\"Remove\"]")
	private WebElement removeButton;

	public InternalPage clickRemoveMovie(){

		removeButton.click();
	    wait.until(alertIsPresent()).accept();
	    return pages.internalPage;
	}

	public boolean waitPageLoaded() {
	    try {
	      ensurePageLoaded();
	      return true;
	    } catch (TimeoutException to) {
	      return false;
	    }
	  }

	public FilmViewPage ensurePageLoaded() {
	    super.ensurePageLoaded();

	    wait.until(presenceOfElementLocated(By.cssSelector("img[alt=\"Edit\"]")));
	    return this;
	  }

}
